// 路由跳转全写在这里面
import Vue from 'vue';
import VueRouter from 'vue-router';
/**解决router重复报错 */
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    // 首页
    path: '/',
    redirect: '/home', // 重定向
    component: () => import('@/App.vue'),
    children: [
      {
        path: '/home',
        component: () => import('@/layout/home'),
        redirect: '/info',
        children: [
          {
            path: '/info',
            component: () => import('@/views/homeinfo'),
          },
          {
            // 商品主页
            path: '/shop',
            component: () => import('@/views/shop'),
          },
          {
            path: '/mobilelist/:id',
            component: () => import('@/components/shopList/onlymobile'),
          },
          {
            // 商品详情
            path: '/pdetails/:id',
            component: () => import('@/views/productDetails'),
          },
          {
            // 博客
            path: '/blog',
            component: () => import('@/views/blog'),
          },
          {
            // 博客详情
            path: '/bloglist/:id',
            component: () => import('@/views/blogList'),
          },
          {
            // 关于我们
            path: '/about',
            component: () => import('@/views/about'),
          },
          {
            // 登录注册
            path: '/login',
            component: () => import('@/layout/login'),
          },

          {
            // 购物车
            path: '/cart',
            component: () => import('@/views/cart'),
          },
          {
            // 个人中心
            path: '/center',
            component: () => import('@/views/center'),
          },
          {
            // 移动端搜索列表
            path: '/search',
            component: () => import('@/views/searchResult'),
          },
          {
            // 订单页面
            path: '/orders',
            component: () => import('@/views/order'),
          },
        ],
      },
    ],
  },
  {
    // 订单页面
    path: '/order',
    component: () => import('@/views/order'),
  },
  {
    path: '/success',
    component: () => import('@/views/order/success'),
  },
  {
    path: '/blogcontent/:id',
    component: () => import('@/views/blog/content'),
  },
  {
    path: '/detail/:id',
    component: () => import('@/views/productDetails'),
  },
  {
    path: '/carts',
    component: () => import('@/views/cart'),
  },
  {
    path: '/historyorder',
    component: () => import('@/views/order/historyorder'),
  },
  {
    // 404页面
    path: '*',
    component: () => import('@/layout/NotFound'),
  },
];

const router = new VueRouter({
  routes,
});

export default router;
